<!doctype html>
<html>
<head>
	<meta charset="utf-8"><meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
	<title>我的</title>
	<link rel="stylesheet" type="text/css" href="../../lib/css/skin.css"/>
</head>
<body>
<div id="root">
	<div class="app_warp">
		<div class="app_head">
			<span class="left back"></span>
			<span class="name">我的</span>
			<span class="right">
				<a href="javascript:;" class="logout" style="display: none" tapmode onclick="logout()">退出</a>
			</span>
		</div>
		<div class="app_main">
			<div class="space"></div>
			<div class="nocontent unlogin animated fadeInUp" style="display: none">
				<img src="../../lib/img/unlogin.png" alt="">
				<div class="text">
					神马？你还没有登录？赶紧...
					<div class="goto_login">
						<a href="javascript:;" tapmode onclick="api.openWin({name:'login',url:'../login/login.html'})">
							去登录
						</a>
					</div>
				</div>
			</div>
			<div class="user_integral_change" style="display: none">
				<div class="userpage_title animated fadeInDown">
					请选择您在艺考中的身份
					<p class="intro">请慎重选择，身份一旦选择后不可更改</p>
				</div>
				<div class="userpage_cont animated fadeInUp">
					<div class="img_sel_top" tapmode onclick="openPage('student')">
						<img src="../../lib/img/img_sel_top.png" alt="">
						<span class="name">
							学生
						</span>
					</div>
					<div class="img_sel_bottom" tapmode onclick="openPage('mechanism')">
						<img src="../../lib/img/img_sel_bottom.png" alt="">
						<span class="name">
							机构
						</span>
					</div>
				</div>
			</div>
			<div id="user_center_list" class="user_center_list animated fadeInUp" style="display: none"></div>
		</div>
	</div>
</div>
<script id="user_center_list_template" type="text/html">
	<div class="topbg" tapmode onclick="openPage('<%:=(type===1?"student":"mechanism")%>')">
	<img src="<%:=avatar%>" alt="">
	<span class="name"><%:=name%></span>
	</div>
	<ul class="app_collist icon_list">
		<li class="space"></li>
		<li class="in" tapmode onclick="getPage('jifen')">
			<span class="icon jifen"></span>
			我的积分
			<i id="jifenval" class="val">
				<%:=integral%>
			</i>
		</li>
		<li class="in" tapmode onclick="getPage('dingdan')">
			<span class="icon dingdan"></span>
			我的订单
		</li>
		<li class="in" tapmode onclick="getPage('xinde')">
			<span class="icon xinde"></span>
			我的心得
		</li>
		<li class="space"></li>
		<li class="in" tapmode onclick="getPage('soucang')">
			<span class="icon soucang"></span>
			我的收藏
		</li>
		<li class="in" tapmode onclick="getPage('xiaoxi')">
			<span class="icon xiaoxi"></span>
			我的消息
		</li>
		<%if(type==2){%>
		<li class="space"></li>
		<li class="in" tapmode onclick="getPage('xuesheng')">
			<span class="icon xuesheng"></span>
			我的学生
		</li>
		<%}%>
	</ul>
</script>
<script>
	var
		getPage = function (name) {
			api.openWin({
				name: name,
				url: name + '.html'
			})
		}, logout = function () {
			_$.db.clear({
				call: function () {
					api.toast({
						msg: '您已经退出登录'
					})
					_$.sleep(function () {
						api.rebootApp();
					}, 2000);
				}
			});
		}, openPage = function (name) {
			api.openWin({
				name: name,
				url: 'usersel.html'
			});
		}, appready = function () {

			_$.db.get({
				call: function (data) {
					if (data.token === null) {
						//未登录
						$('.unlogin').show();
					} else {
						//data.type=0;
						if (data.type === 3) {
							//角色未确定
							$('.logout,.user_integral_change').show();
						} else {
							//角色已经确定
							_$.template('user_center_list_template', data, function (html) {
								$('#user_center_list').html(html);
								$('.logout,#user_center_list').show();
							})
						}
						$('.logout').show();
					}
				}
			})

			//check loginStatusChange===true
			api.addEventListener({
				name: 'viewappear'
			}, function () {

				console.log('viewappear');
				_$.db.get({
					key: 'appStatus',
					call: function (data) {

						function initThis(){
							api.execScript({
								name:'home',
								script:'setUserImg()'
							})
							_$.sleep(function () {
								api.execScript({
									script:'window.location.reload()'
								})
							}, 500);
							_$.db.ext({
								key: 'appStatus',
								val: data
							});
						}

						if(data==='_unset_'){
							data={
								loginStatusChange:false,
								userTypeChange:false
							}
						}

						if (data.loginStatusChange) {
							console.log('loginStatusChange')
							data.loginStatusChange = !data.loginStatusChange;
							initThis()
						}
						if (data.userTypeChange) {
							console.log('userTypeChange')
							data.userTypeChange = !data.userTypeChange;
							initThis()
						}
					}
				})
			});

		};
</script>
<script src="../../lib/js/config.js"></script>
<script src="../../lib/js/jquery.js"></script>
<script src="../../lib/js/common.js"></script>
</body>
</html>